"use strict";
/**
 * 类, 构造, this
 * 继承 抽象类
 * 接口
 * 属性封装
 * 泛型
 */
// 类, 构造, this
class Person {
    // 构造函数
    constructor(name, age) {
        this.name = name;
        this.age = age;
        Person.count++;
    }
    // 类成员
    speak() {
        console.log(`my name is ${this.name}, age is ${this.age}`);
    }
    static getCount() {
        return Person.count;
    }
}
// 类属性
Person.count = 10;
const p1 = new Person("rose", 30);
console.log(p1, Person.count);
console.log(Person.getCount());
class Dog {
    // 内存初始化(系统清理内存), 默认初始化(语言类型默认值),
    // 构造初始化(类成员初始值) -> 理解三种初始化时间, 目的
    constructor(name, age) {
        // console.log('calling constructor: 创建新实例时调用')
        this.name = name;
        this.age = age;
    }
    bark() {
        console.log(this.name, 'bark');
    }
}
const d1 = new Dog('旺财', 2);
const d2 = new Dog('大黄', 4);
const d3 = new Dog('小黄', 1);
console.log(d1);
console.log(d2);
console.log(d3);
(function () {
    class Animal {
        constructor(name, age) {
            this.name = name;
            this.age = age;
        }
        speak() {
            console.log('animal speak');
        }
    }
    // 继承Animal
    class Dog extends Animal {
        // constructor(name: string, age: number) {
        //     super(name, age)
        // }
        speak() {
            console.log('dog speak');
        }
    }
    class Cat extends Animal {
        constructor(name, age, type) {
            super(name, age);
            // 添加属性
            this.type = type;
        }
        speak() {
            // super.speak() super 用来代替指向父类对象的内存部分
            console.log('cat speak');
        }
        //支持重载, 但是不支持重载
        //speak(a:number):number {}
        catchMouse() {
            console.log('抓老鼠');
        }
    }
    const d1 = new Dog('小黄', 30);
    console.log(d1);
    d1.speak();
    const c1 = new Cat('小猫', 2, '狸花猫');
    console.log(c1);
    c1.speak();
    // 抽象类
    class Walker {
        walk() {
        }
    }
    // 抽象类: 不允许实例化
    // const w:Walker = new Walker()
})();
// 接口实现
class Eagle {
    read() {
        return 0;
    }
    compareTo(o) {
        return 0;
    }
}
// 属性封装
// ts 支持 public private protected 访问修饰符
;
(function () {
    let Gender;
    (function (Gender) {
        Gender[Gender["MALE"] = 0] = "MALE";
        Gender[Gender["FEMALE"] = 1] = "FEMALE";
    })(Gender || (Gender = {}));
    // 封装保护
    class Person {
        constructor(name, age, gender) {
            this._name = name;
            this._age = age;
            this._gender = gender;
        }
        // typescript 属性读取和写入的方法
        // 实际访问的时候, 和直接读取属性一样, 不需要用方法调用语法
        get name() {
            return this._name;
        }
        set name(value) {
            this._name = value;
        }
    }
    const p1 = new Person('孙悟空', 2087, Gender.MALE);
    // 未封装, 属性可以被任意修改, 不安全, 大规模开发的不确定性太强了
    // 可维护性, 可扩展性降低
    p1.name = 'abc';
    // p1.age = 30
    console.log(p1);
})();
(function () {
    // 执行时确定K具体是什么类型
    function fn(a) {
        return a;
    }
    // 指定泛型
    const k1 = fn(1);
    const k2 = fn('1');
    console.log(k1, k2);
    console.log(typeof k1, typeof k2);
    // 泛型边界限定  extends 上界  super 下界
    // <T extends Number>  <T super Number> 下边界
})();
